<?php

namespace App\Library\Utils;

class Str
{

    public static function endsWith($str, $needle): bool
    {
        if (is_array($needle)) {
            foreach ($needle as $n) {
                if (static::endsWith($str, $n)) {
                    return true;
                }
            }
            return false;
        }

        $length = strlen($needle);
        if ($length == 0) {
            return true;
        }
        return (substr($str, -$length) === $needle);
    }

    public static function startWith($haystack, $needle): bool
    {
        $length = strlen($needle);
        if ($length == 0) {
            return true;
        }
        return (substr($haystack, $length) === $needle);
    }
}